//
//  XQNotificationView.m
//  Demo
//
//  Created by 包月兴 on 16/7/16.
//  Copyright © 2016年 包月兴. All rights reserved.
//

#import "XQNotificationView.h"
#import "AKTKit.h"
@implementation XQNotificationView
/*
 * Show notification
 * 显示通知消息
 * @y: View from the top to the top of the screen。
 * @y: view的顶部到屏幕顶部的距离
 * @message: Message content to be displayed。
 * @message: 需要显示的消息内容
 */
+ (void)showWithActiveStyle:(BOOL)activeStyle andMessage:(NSString *)message {
    UIView *container;
    container = [UIView new];
    static id window = nil;
    UIWindow *windowTemp = [[UIWindow alloc]initWithFrame:(CGRectMake(0,60, mAKT_SCREENWITTH, 36))];
    window = windowTemp;
    [windowTemp setWindowLevel:(UIWindowLevelStatusBar)];
    [windowTemp makeKeyAndVisible];
    [windowTemp addSubview:container];
    container.frame = CGRectMake(0, -36, mAKT_APPDELEGATE.keyWindow.width, 36);
    [container setClipsToBounds:YES];
    container.backgroundColor = !activeStyle? mAKT_Color_Color(0xff, 0x81, 0x81, 1):mAKT_Color_Color(116, 230, 124, 1);
    // Add message label
    UILabel *label = [UILabel new];
    [container addSubview:label];
    [label setTextColor:mAKT_Color_Text_255];
    [label setFont:mAKT_Font_14];
    [label setTextAlignment:(NSTextAlignmentCenter)];
    label.text = message;
    [label sizeToFit];
    UIImageView *imgv = [UIImageView new];
    [container addSubview:imgv];
    imgv.image = mAKT_Image(@"img_cry");
    [imgv sizeToFit];
    
    CGFloat totalWidth = imgv.width+label.width+6;
    imgv.frame = CGRectMake((container.width-totalWidth)/2, (container.height-imgv.height)/2, imgv.width, imgv.height);
    label.frame = CGRectMake(imgv.x+imgv.width+6, (container.height-label.height)/2, label.width, label.height);
    [UIView animateWithDuration:.5 delay:0 usingSpringWithDamping:1 initialSpringVelocity:.5 options:0 animations:^{
        container.frame = CGRectMake(0, 0, container.width, container.height);
    } completion:^(BOOL finished) {
        [UIView animateWithDuration:.5 delay:2 usingSpringWithDamping:1 initialSpringVelocity:.5 options:0 animations:^{
            container.frame = CGRectMake(0, -container.height-60, container.width, container.height);
        } completion:^(BOOL finished) {
            if (window == windowTemp) {
                window = nil;
            }
        }];
    }];
}

@end
